import { createBrowserRouter } from "react-router-dom";
import Layout from '@/pages/Layout'
import Login from '@/pages/Login'
import AuthRoute from "../components/AuthRoute";
// import Home from "../pages/Home";
import { lazy, Suspense } from "react";
// import Article from "../pages/Article";
// import Publish from "../pages/Publish";
import ErrorPage from "../pages/ErrorPage";

//懒加载
const Publish = lazy(() => import('@/pages/Publish'))
const Article = lazy(() => import('@/pages/Article'))
const Home = lazy(() => import('@/pages/Home'))


const router = createBrowserRouter([
    {
        path: '/',
        element: <AuthRoute><Layout /></AuthRoute>,
        errorElement: <ErrorPage />,
        children: [
            {
                errorElement: <ErrorPage />,
                children: [{
                    index: true,
                    element: (
                        <Suspense fallback={'加载中'}>
                            <Home />
                        </Suspense>
                    )
                }, {
                    path: 'article',
                    element: (
                        <Suspense fallback={'加载中'}>
                            <Article />
                        </Suspense>
                    )
                }, {
                    path: 'publish',
                    element: (
                        <Suspense fallback={'加载中'}>
                            <Publish />
                        </Suspense>
                    )
                }]
            }
        ]
    }, {
        path: '/login',
        element: <Login />
    }
])

export default router